package club.haomoon.front.controller;


import club.haomoon.core.common.AjaxResult;
import club.haomoon.core.common.PageResult;
import club.haomoon.front.config.CmsFrontThreadLocal;
import club.haomoon.front.data.pay.RechargeConfigData;
import club.haomoon.front.data.pay.RechargeRecordData;
import club.haomoon.front.service.IRechargeService;
import club.haomoon.front.validate.common.PageValidate;
import club.haomoon.front.validate.common.RechargeValidate;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import jakarta.annotation.Resource;
import java.util.Map;

@RestController
@RequestMapping("/api/recharge")
@Tag(name = "充值管理")
public class RechargeController {

    @Resource
    IRechargeService iRechargeService;

    @GetMapping("/config")
     @Operation(summary = "充值配置")
    public AjaxResult<Object> config() {
        Integer userId = CmsFrontThreadLocal.getUserId();

        RechargeConfigData vo = iRechargeService.config(userId);
        return AjaxResult.success(vo);
    }

    @GetMapping("/lists")
     @Operation(summary = "充值记录")
    public AjaxResult<Object> lists(@Validated PageValidate pageValidate) {
        Integer userId = CmsFrontThreadLocal.getUserId();

        PageResult<RechargeRecordData> list = iRechargeService.record(userId, pageValidate);
        return AjaxResult.success(list);
    }

    @PostMapping("/recharge")
     @Operation(summary = "充值下单")
    public AjaxResult<Object> recharge(@Validated @RequestBody RechargeValidate rechargeValidate) {
        Integer userId = CmsFrontThreadLocal.getUserId();
        Integer terminal = CmsFrontThreadLocal.getTerminal();

        Map<String, Object> result = iRechargeService.placeOrder(userId, terminal, rechargeValidate);
        return AjaxResult.success(result);
    }

}
